package com.jason.game.online.remote

import com.cby.library.common.network.RetrofitManager
import com.cby.library.tool.CbyTools


object ApiSource {

    /**
     * api接口版本号
     */
    const val API_VERSION_20 = "/v20"

    /** 正式地址 */
    private const val URL_API_DOMAIN = "https://api.h5wan.4399sj.com"
    private const val URL_CDN_DOMAIN = "https://cdn.h5wan.4399sj.com"
    private const val URL_FORUM_DOMAIN = "https://my.4399.com"

    /** 测试地址 */
    private const val URL_API_DOMAIN_TEST = "https://t.api.h5wan.4399sj.com"
    private const val URL_CDN_DOMAIN_TEST = "https://t.cdn.h5wan.4399sj.com"
    private const val URL_FORUM_DOMAIN_TEST = "http://bbs.t2.my.4399.com"

    private fun getApiUrl() : String {
        return if(CbyTools.isTest()) {
            URL_API_DOMAIN_TEST
        }else{
            URL_API_DOMAIN
        }
    }

    private fun getCdnUrl() : String {
        return if(CbyTools.isTest()) {
            URL_CDN_DOMAIN_TEST
        }else{
            URL_CDN_DOMAIN
        }
    }

    /**
     * Api的接口对象
     *
     * @param service Class<T>
     * @return T
     */
    fun <T> getApiService(service: Class<T>): T {
        return RetrofitManager.createRetrofit(getApiUrl()).create(service)
    }

    /**
     * Cdn的接口对象
     *
     * @param service Class<T>
     * @return T
     */
    fun <T> getCdnService(service: Class<T>): T {
        return RetrofitManager.createRetrofit(getCdnUrl()).create(service)
    }

}